package cn.jtfadmin.base.lang.common.domain.entity;


import org.springframework.stereotype.Component;

/**
 * id实体监听器<br/>
 * 当保存时设置id
 *
 * @author jtf
 * @since 0.0.1
 * @see EntityListener
 * @see EntityIdGen
 */
@Component
public class IdEntityListener implements EntityListener {


    private EntityIdGen entityIdGen = new UUIDEntityIdGen();

    /**
     * 设置是否内置
     *
     * @param object 实体 必须是 BuildInAbleEntity
     */
    public void prePersist(Object object) {
        if (object instanceof IdEntity) {
            ((IdEntity) object).setId(entityIdGen.genId());
        }
    }

}
